﻿using Prism.Commands;
using Prism.Ioc;
using Prism.Regions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls.Primitives;
using Wpf.Netdisk.Extensions;
using Wpf.Netdisk.Models;
using Wpf.Netdisk.ViewModels.Base;

namespace Wpf.Netdisk.ViewModels.MainListItem
{
    public class IndexViewModel : NavigationViewModel
    {
        #region 属性

        private ObservableCollection<MenuBar> menuBars;
        private readonly IRegionManager _regionManager;

        public ObservableCollection<MenuBar> MenuBars
        {
            get { return menuBars; }
            set { menuBars = value; RaisePropertyChanged(); }
        }

        private IRegionNavigationJournal journal;
        /// <summary>
        /// 导航属性
        /// </summary>
        public DelegateCommand<MenuBar> NavigateCommand { get; private set; }
        private Visibility visibility;

        public Visibility Visibility
        {
            get { return visibility; }
            set { visibility = value; RaisePropertyChanged(); }
        }

        public DelegateCommand<object> ListVisibilityCommand { get; private set; }
        #endregion
        public IndexViewModel(IContainerProvider containerProvider, IRegionManager regionManager) : base(containerProvider)
        {
            CreateMenuBar();
            this._regionManager = regionManager;
            NavigateCommand=new DelegateCommand<MenuBar>(Navigate);
            ListVisibilityCommand = new DelegateCommand<object>(ListVisibility);
        }

        private void ListVisibility(object obj)
        {
            var info = (Visibility)obj;
            if (info== Visibility.Visible)
            {
                Visibility = Visibility.Hidden;
            }
            else
            {
                Visibility = Visibility.Visible;
            }
            var regions = _regionManager.Regions[PrismManager.ChildrenViewRegionName];
            regions.RequestNavigate("MyFolderView");
        }

        private void Navigate(MenuBar obj)
        {
            if (obj == null || string.IsNullOrWhiteSpace(obj.NameSpace))
            {
                return;
            }
            var regions = _regionManager.Regions[PrismManager.ChildrenViewRegionName];
            regions.RequestNavigate(obj.NameSpace, back =>
            {
                journal = back.Context.NavigationService.Journal;

            });
        }
        void CreateMenuBar()
        {
            MenuBars=new ObservableCollection<MenuBar>();
            //Todo 替换为接口获取
            MenuBars.Add(new MenuBar() { Icon = "/Img/Main/zuijinliulan.png", Title = "最近", NameSpace = "RecentView" });
            MenuBars.Add(new MenuBar() { Icon = "/Img/Main/ImgIcon.png", Title = "图片", NameSpace = "" });
            MenuBars.Add(new MenuBar() { Icon = "/Img/Main/video.png", Title = "视频", NameSpace = "" });
            MenuBars.Add(new MenuBar() { Icon = "/Img/Main/fileIcon.png", Title = "文档", NameSpace = "" });
            MenuBars.Add(new MenuBar() { Icon = "/Img/Main/musicIcon.png", Title = "音乐", NameSpace = "" });
            MenuBars.Add(new MenuBar() { Icon = "/Img/Main/btIcon.png", Title = "种子", NameSpace = "" });
            MenuBars.Add(new MenuBar() { Icon = "/Img/Main/otherIcon.png", Title = "其他", NameSpace = "" }); 
            MenuBars.Add(new MenuBar() { Icon = "/Img/Main/SecretsIcon.png", Title = "隐藏空间", NameSpace = "" }); 
        }
    }
}
